<include file="Flow:header"/>
<body>
    <div class="wraper">
        <div class="head clearfix">
            <a href="javascript:history.back(-1);" class="iconfont icon-zuojiantou pull-left"></a>
            <span class="head-name pull-left">确认信息</span>
        </div>
        <div class="form-box">
            <div class="form-list">
                即将为以下用户办理移动预缴费业务，充值100元得600
                元话费，分30个月返还，未成功用户将在1-3个工作日返
                还充值金额.
            </div>
            <div class="form-list">
                <p class="tb-mode"><span class="field tb-cell">真实姓名</span><span class="tb-cell">{BEESCRM:$ismobile['real_name']}</span></p>
                <p class="tb-mode"><span class="field tb-cell">手机号码</span><span class="tb-cell">{BEESCRM:$ismobile['mobile']}</span></p>
                <p class="tb-mode"><span class="field tb-cell">{BEESCRM:$sim_pwd}{BEESCRM:$identity_num}</span><span class="tb-cell">{BEESCRM:$ismobile['sim_pwd']}{BEESCRM:$ismobile['identity_num']}</span></p>
                <p class="tb-mode"><span class="field tb-cell">交易金额</span><span class="tb-cell">{BEESCRM:$isConfig}</span></p>
            </div>
        </div>
        <a class="normal-btn" id="payMent">确认并付款</a>
    </div>
    <div class="pop-box" style="display: none" id="isSuccess">
        <div class="main">
            <p class="iconfont icon-shenheshibai"></p>
            <div class="main-text">
                <p class="stress text-center">申请已提交</p>
                <p class="text-center">您已预约成功，请等待工作人员与您联系</p>
            </div>
        </div>
    </div>
    <input type="hidden" value="{BEESCRM:$conf_id}" id="conf_id">
    <input type="hidden" value="{BEESCRM:$openid}" id="openid">
    <!--<input type="hidden" value="{BEESCRM:$ismobile['real_name']}" id="realname">-->
    <!--<input type="hidden" value="{BEESCRM:$ismobile['mobile']}" id="mobile">-->
    <script src="/assets/base/flow/js/jquery-2.1.0.min.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="/assets/bower_components/sweetalert/lib/sweet-alert.min.js"></script>
    <script src="/assets/base/flow/js/jq.utils.js"></script>
    <script>
        var conf_id = $("#conf_id").val();
        var openid = $("#openid").val();
//        var mobile = $("#mobile").val();
//        $("#payMent").on('click',function(){
//            $.ajax({
//                url:"/base/flow/checkuser/conf_id/"+conf_id,
//                type:"post",
//                dataType:"json",
//                data:{mobile: mobile},
//                success:function(msg)
//                {
//                    if(msg.status == 'S'){
//                        $.ajax({
//                            url: "/base/flow/createOrder/conf_id/" + conf_id,
//                            type: "post",
//                            dataType: 'json',
//                            data: {confirm: 1, openid: openid},
//                            success: function (data)
//                            {
//                                if (data.status == 'S')
//                                {
//                                    //$("#isSuccess").show();
//                                    var wxpay = $.parseJSON(data.wxpay);
//                                    pay(wxpay);
//                                } else {
//                                    $.alert('error', data.message);
//                                    return false;
//                                }
//                            }
//                        });
//                    }else {
//                        $.alert('error',msg.message);
//                        return false;
//                    }
//                }
//            })
//        });
        $("#payMent").on('click', function () {
//            alert(openid);
            $.ajax({
                url: "/base/flow/createOrder/conf_id/" + conf_id,
                type: "post",
                dataType: 'json',
                data: {confirm: 1, openid: openid},
                success: function (data)
                {
                    if (data.status == 'S')
                    {
                        //$("#isSuccess").show();
                        var wxpay = $.parseJSON(data.wxpay);
                        pay(wxpay);
                    } else {
                        $.alert('error', data.message);
                        return false;
                    }
                }
            });

        });

        //微支付
        function pay(wxpay) {
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            } else {
                WeixinJSBridge.invoke(
                        'getBrandWCPayRequest',
                        wxpay,
                        function (res) {
    //                        WeixinJSBridge.log(res.err_msg);
    //                        alert(res.err_msg);return false;

                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                paySuccess();
                            } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                $.alert('error', '付款已取消');
                                setTimeout('jumpurl()', 2000);
                                return false;
                            } else {
                                $.alert('error', '调用微支付失败');
                                return false;
                            }
                        }
                );
            }
        }

        function paySuccess() {
            jumpurl();
        }
        function payError()
        {
            location.href = "/base/flow/index/conf_id/" + conf_id;
        }
        function jumpurl()
        {
            location.href = "/index.php?g=base&m=flow&a=orderList&conf_id=" + conf_id;
        }
    </script>
</body>
</html>
